var server = require('./utils/server');
App({
	onLaunch: function () {
    wx.login({
      success: function (res) {
        if (res.code) {
          console.log(res.code);
          // 将code发送给服务器，由服务器向微信服务器发送请求获取用户唯一标识和会话密钥
        } else {
          console.log('登录失败！' + res.errMsg);
        }
      }
    })
  },
	onShow: function () {
		console.log('App Show')
	},
	onHide: function () {
		console.log('App Hide')
	},
	globalData: {
		hasLogin: false,
		cartList: [],
		userInfo: [],
	},
	rd_session: null,
	login: function() {
		var self = this;
		wx.login({
			
		});
	},
	getUserInfo: function() {
		var self = this;
		wx.getUserInfo({
			success: function(res) {
				self.globalData.userInfo = res.userInfo;
				server.getJSON('dwq/WxAppApi/checkSignature.php', {
					rd_session: self.rd_session,
					signature: res.signature,
					raw_data: res.rawData
				}, function (res) {
					if (!res.data.is_pass) {
						// TODO:验证有误处理
						self.login();
					}
				});
			}			
		});
	}
})
